<?php
namespace Admin\Controller;

use Admin\Controller\CommonController;

class IndexController extends CommonController
{

    public function index()
    {
        $this->display('main');
    }

    // 统计图
    public function workbench(){
    	$game = M('game')->field('game,gameid,poster')->select();
    	$app = M('app')->field('app,appid')->select();
    	// 饼图
    	$bingtu = M('type')->field('type,typeid')->select();
    	foreach ($bingtu as $k => $v) {
    		$typeid = $v['typeid'];
    		$bingtu[$k]['gnum'] = M('game')->where("typecode='$typeid'")->count();
    	}
        // 一周日期显示
        date_default_timezone_set('PRC'); 
        for ($i=-7; $i <=-1; $i++) { 
            $time[] = date('Y-m-d', strtotime($i.'days'));
            $begin =  strtotime(date('Y-m-d'))+86400*$i;
            $end =  strtotime(date('Y-m-d'))+86400*($i+1);
            $lius[] = M('recharge_record')->where("createtime>=$begin and createtime<$end")->count();
        }
        $liu = implode(',', $lius);
        $computer = M('computer')->field('computerid,title')->select();
        foreach ($computer as $k => $v) {
    		$computerid = $v['computerid'];
    		$computer[$k]['cnum'] = M('game_server')->where("computerid='$computerid'")->count();
    	}
        $this->assign("app",$app);
        $this->assign("game",$game);
        $this->assign("computer",$computer);
        $this->assign("time",$time);
        $this->assign("liu",$liu);
    	$this->assign("bingtu",$bingtu);
        $this->display('workbench');
    }

    // 首页显示数量
    public function shuliang(){
    	$data=array();
    	$data['game'] = M('game')->count();
    	$data['app'] = M('app')->count();
    	$data['computer'] = M('computer')->count();
    	$data['game_server'] = M('game_server')->count();
    	$data['user'] = M('user')->count();
    	$data['item'] = M('item')->count();

    	$this->ajaxReturn($data);
    }
}


